package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.MealOrderEmail;
import com.ruoyi.system.service.impl.MealOrderReminderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 订餐提醒Controller
 */
@RestController
@RequestMapping("/mealorder/order")
//@CrossOrigin(origins = "*") // 允许跨域请求
public class MealOrderReminderController {

    @Autowired
    private MealOrderReminderServiceImpl mealOrderReminderService;

    /**
     * 发送未填写订餐状态提醒邮件
     */
    @PreAuthorize("@ss.hasPermi('mealorder:order:list')")
    @PostMapping("/sendCustomEmail")
    public AjaxResult sendReminders(@RequestBody MealOrderEmail emailRequest) {
        try {
            // 这里需要修改实现，因为原来的方法不接受参数
            // 可以直接使用邮件服务发送邮件
            // 调用服务层发送邮件
            mealOrderReminderService.sendUnfilledMealOrderReminders(
                    emailRequest.getTo(),
                    emailRequest.getSubject(),
                    emailRequest.getContent()
            );
            return AjaxResult.success("提醒邮件发送成功");
        } catch (Exception e) {
            return AjaxResult.error("发送提醒邮件失败: " + e.getMessage());
        }
    }
}
